package com.zxh.service;

import com.zxh.dao.BaseDao;
import com.zxh.dao.user.UserDao;
import com.zxh.dao.user.UserDaoImpl;
import com.zxh.pojo.User;

import java.sql.Connection;
import java.sql.SQLException;

public class UserServiceImpl implements UserService{
    private UserDao userD;

    public  UserServiceImpl(){
        userD  = new UserDaoImpl();
    }

    @Override
    public User login(String userCode, String password) {
        User us = null;

        Connection con = BaseDao.getConnection();
        try {
           us  = userD.getLoginUser(con, userCode);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            BaseDao.closeResult(con, null,null);
        }
        if ((null != us) & (!us.getUserPassword().equals(password)))
            return us = null;

        return us;
    }
}
